package windowFactoryPackage;

import java.awt.event.*;
import javax.swing.*;

public class DownloadButton extends JButton {
	// now that we know what prog you want, use int attr instead of arrayList

	Query q = new Query();

	public DownloadButton() {
		super("Download");
		this.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				// //this is for the test ArrayList view
				for (int i = 0; i < ResultsPanel.dbArrayList.size(); i++) {
					if (e.getSource() == ResultsPanel.dbArrayList.get(i)) {
						// makes sure user is logged in to proceed
						if (tester.UserIsLoggedIn) {
							System.out.println("DownloadButton pressed at position " + i);

							// set values for the downloads window and open it
							Query.program_id = Query.progId.get(i);
							Query.ip_id = Query.ipId.get(i);
							// call query to return program name to display in
							// the download window
							q.searchWindowDownload();
							
							//test if file has download
							q.testDownloadAvailable();
							if(!Query.testDownloadAvailable.equals("0")){
								WindowGenerator.generateDownloadWindow();
							} else {
								JOptionPane.showMessageDialog(null,"Download Not Available!");
							}
								
						} else
							JOptionPane.showMessageDialog(null,
									"You must login to download this program.");

					}
				}

			}

		});
	}
}